<template>
    <div>
        
        <h1>会员修改</h1>
        {{ info }}
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">编号</td>
                    <td>{{ info.Code }}</td>
                </tr>
                <tr>
                    <td align="right">手机号</td>
                    <td><input type="text" v-model="info.Phone"></td>
                </tr>
                <tr>
                    <td align="right">会员名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">会员身份证</td>
                    <td><input type="text" v-model="info.Card"></td>
                </tr>
                <tr>
                    <td align="right">等级名称</td>
                    <td>
                        <select v-model="info.LevelName">
                            <option value="">请选择</option>
                            <option :value="itme.Name" v-for="itme in list.a":key="itme.Id"> {{ itme.Name }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">生日</td>
                    <td><input type="date" v-model="info.BirthDay"></td>
                </tr>
                 <tr>
                    <td align="right">性别</td>
                    <td><input type="radio" name="data" v-model="info.Sex" value="1">男
                        <input type="radio" name="data" v-model="info.Sex" value="0">女
                    </td>
                </tr>
                <tr>
                    <td align="right">积分</td>
                    <td><input type="text" v-model="info.Score"></td>
                </tr>
                <tr>
                    <td align="right">余额</td>
                    <td>
                        <input type="text" v-model="info.Money">
                    </td>
                </tr>
                <tr>
                    <td align="right">爱好</td>
                    <td>
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费吃早餐">免费吃早餐
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费停车">免费停车
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费洗澡">免费洗澡
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费看电影">免费看电影
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费看篮球场">免费看篮球场
                    <input type="checkbox" name="te" v-model="info.Likes" value="免费晚饭">免费晚饭
                </td>
                </tr><tr>
                    <td align="right">会员简介</td>
                    <td>
                        <textarea v-model="info.Desc" ></textarea>
                    </td>
                </tr>
                 <tr>
                    <td align="right"></td>
                    <td><input type='button' value="修改" class="btn btn-primary" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  Id:route.query.Id,
  Code: '',
  Phone: '',
  Name: '',
  Card: '',
  LevelName: '',
  BirthDay: '',
  Sex: '',
  Score: '',
  Money: '',
  Likes:[],
  Desc: '',
  IsBreak:''
  
})
let list:any=reactive({
    a:[]
})
onMounted(()=>{
    getlist();
    getFind();
})

const getFind=()=>{
    axios({
        url:'/api/Hy/GetFind',
        method:'get',
        params:{
            Id:route.query.Id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info,res.data)
        info.BirthDay=res.data.BirthDay.substring(0,10);
        info.Likes=res.data.Likes.split(',')
    })
    .catch((err)=>{
        console.log(err);
        
    })
}





const getlist=()=>{
    axios({
        url:'/api/Hy/All',
        method:'get'
    })
    .then((res)=>{
        console.log(res);
        list.a=res.data;
    })
    .catch((err)=>{
        console.log(err);
        
    })

}
const ok=()=>{
    info.Likes=info.Likes.toString();
    axios({
        url:'/api/Hy/update',
        method:'put',
        data:info
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1)
    {
        alert('会员名称重复');
        return;
    }
    if(res.data>0)
    {
        alert('修改成功');
        router.push('/showhy')
        return;
    }
    else
    {
        alert('修改失败');
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>